package cn.chen.thread;

import java.util.Date;

public class Tools2 {

    public static ThreadLocal<Date> t1 = new ThreadLocal<>();

}

class Thread1 extends Thread{
    @Override
    public void run() {
        try {
            for(int i = 0;i < 20;i ++){
                if(Tools2.t1.get() == null) Tools2.t1.set(new Date());
                System.out.println("A "+ Tools2.t1.get());
                    Thread.sleep(100);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class Thread2 extends Thread{
    @Override
    public void run() {
        try {
            for(int i = 0;i < 20;i ++){
                if(Tools2.t1.get() == null) Tools2.t1.set(new Date());
                System.out.println("B " + Tools2.t1.get());
                Thread.sleep(100);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class Run2{
    public static void main(String[] args) {
        try {
            Thread1 thread1 = new Thread1();
            thread1.start();
            Thread.sleep(1000);
            Thread2 thread2 = new Thread2();
            thread2.start();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}